from flask import current_app, request, jsonify
from src.api.controllers.classification_controller import ClassificationController
from src.utils.logger import log_info

def register_classification_routes(bp):
    controller = ClassificationController()
    
    @bp.route('/classification/process', methods=['POST'])
    def process_directory():
        data = request.json
        directory = data.get('directory')
        settings = {
            'enable_classification': data.get('enable_classification', True),
            'enable_translation': data.get('enable_translation', True),
            'ad_detection': data.get('ad_detection', True),
            'watermark_detection': data.get('watermark_detection', True),
            'language': data.get('language', 'VN'),
            'api_key': data.get('api_key', ''),
            'sleep_time': data.get('sleep_time', 0),
        }
        
        log_info(f"接收到分类请求: 目录={directory}")
        result = controller.process_directory(directory, settings)
        return jsonify(result)
    
    @bp.route('/classification/status', methods=['GET'])
    def get_status():
        result = controller.get_status()
        return jsonify(result)
    
    @bp.route('/classification/stop', methods=['POST'])
    def stop_processing():
        log_info("接收到停止分类请求")
        result = controller.stop_processing()
        return jsonify(result)